package BlogService.model.daoHql;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

/**
 * @author tony
 *
 */
public class HibernateUtil {
	
	private static SessionFactory sessionFactory;
	
	public static SessionFactory configureSessionFactory() throws HibernateException {
		
		Configuration configuration=new Configuration().configure(); // configures settings from hibernate.cfg.xml
		
		StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
		
		// If you miss the below line then it will complaing about a missing dialect setting
		serviceRegistryBuilder.applySettings(configuration.getProperties());
		
		ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
		
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		
		return sessionFactory;
	}
	
}
